package com.tencent.sr.iris.basic.mp.dependency;

import com.alibaba.fastjson.JSON;
import com.tencent.sr.iris.basic.service.interfaces.client.CommonConfigClient;
import com.tencent.sr.iris.basic.service.interfaces.request.CommonConfigForceRequest;
import com.tencent.sr.iris.basic.service.interfaces.response.CommonConfigResponse;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.springbootstarter.route.TsrContextHolder;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CommonConfigDependency {
    @Resource
    private CommonConfigClient commonConfigClient;

    public List<CommonConfigResponse> queryForceConfigs(CommonConfigForceRequest request) {
        try {
            HttpResult<List<CommonConfigResponse>> result = commonConfigClient.queryForceConfigs(request);
            if (result != null && result.isSuccess()) {
                return result.getData();
            }
        } catch (Exception e) {
            try {
                log.error("queryForceConfigs error,request:{},systemTags:{}", JSON.toJSONString(request), JSON.toJSONString(TsrContextHolder.get().getSystemTags()),e);
            } catch (Exception ex) {
                log.error("queryForceConfigs print log error,request:{}", JSON.toJSONString(request), ex);
            }
            throw e;
        }
        return null;
    }
}
